const state = {
  platform: '',
  timeDiff: '',
  appChannelCode: '',
  channelCode: '',
  keepAliveList: [] // 保活列表,
}
const mutations = {
  SET_PLATFORM: (state, platform) => {
    state.platform = platform
  },
  SET_TIMEDIFF: (state, timeDiff) => {
    state.timeDiff = timeDiff
  },
  SET_APPCHANNELCODE: (state, appChannelCode) => {
    state.appChannelCode = appChannelCode
  },
  SET_CHANNELCODE: (state, channelCode) => {
    state.channelCode = channelCode
  },
  SET_H5ENCRYPT: (state, h5Encrypt) => {
    state.h5Encrypt = h5Encrypt
  },
  ADD_KEEPALIVEITEM: (state, keepAliveItem) => {
    if (!state.keepAliveList.includes(keepAliveItem)) {
      state.keepAliveList.push(keepAliveItem)
    }
  },
  DELETE_KEEPALIVEITEM: (state, keepAliveItem) => {
    const index = state.keepAliveList.indexOf(keepAliveItem)
    if (index > -1) {
      state.keepAliveList.splice(index, 1)
    }
  }
}
const getters = {
  getIsWechat: () => {
    const userAgent = navigator.userAgent.toLowerCase()
    return /micromessenger/.test(userAgent)
  }
}
export default {
  state,
  mutations,
  getters
}
